package logic

import (
	"api/internal/svc"
	"api/internal/types"
	"cart_srv/carl"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type CarlListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCarlListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CarlListLogic {
	return &CarlListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CarlListLogic) CarlList(req *types.GoodsListRequest) (resp *types.RegMsgResponse, err error) {
	// todo: 购物车列表

	//模拟用户id
	userId := 1

	list, err := l.svcCtx.CarlSrv.CarlList(l.ctx, &carl.CarlListRequest{UserId: int64(userId)})
	if err != nil {
		return &types.RegMsgResponse{
			Code: -1,
			Msg:  "服务器错误",
			Data: nil,
		}, err
	}

	return &types.RegMsgResponse{
		Code: 0,
		Msg:  "查询成功",
		Data: map[string]interface{}{
			"list": list.CarlList,
		},
	}, err
}
